import pandas as pd

if __name__ == '__main__':
    path = r"C:\Users\lvsk\Desktop\aaa.csv"
    path_w = r"C:\Users\lvsk\Desktop\aaa_2.csv"
    df1 = pd.read_csv(path, encoding='utf-8', sep='\t',
                      index_col=False, usecols=[0, 1, 3, 6, 8, 9, 11])
    df1['操作日期'] = df1['操作日期'] + ' ' + df1['操作时间']
    del df1['操作时间']
    df1['查询航班起飞'] = df1['查询航班起飞'] + '-->' + df1['查询航班到达'] + ' ' + df1['查询去程时间']
    df1.rename(columns={'查询航班起飞': '航班'}, inplace=True)
    del df1['查询航班到达']
    del df1['查询去程时间']
    # print(df1.iloc[0:2, 0:2])
    # print(df1.iloc[1])
    event = set()
    for i in df1['操作事件']:
        event.add(i)
    for num, i in enumerate(event, 1):
        print(str(num) + ' : ' + str(i))
    df1 = df1.fillna('-')
    df1.sort_values(by='操作事件', axis=0, ascending=True, inplace=True)
    df1.sort_values(by='航班', axis=0, ascending=True, inplace=True)
    for num, loc in enumerate(df1.itertuples()):
        if getattr(loc, "操作事件") == '分享' or \
                getattr(loc, "操作事件") == '航班检索-查询成功' or \
                getattr(loc, "操作事件") == '退改操作-查询' or \
                getattr(loc, "操作事件") == '其他操作' or \
                getattr(loc, "操作事件") == '选座相关查询或申请' or \
                getattr(loc, "操作事件") == '注册&登录' or \
                getattr(loc, "操作事件") == '退改操作-成功' or \
                getattr(loc, "操作事件") == '进入页面' or \
                getattr(loc, "操作事件") == '我的行程-查询' or \
                getattr(loc, "操作事件") == '选餐相关查询或申请' or \
                getattr(loc, "操作事件") == '退改操作-退票' or \
                getattr(loc, "操作事件") == '活动营销' or \
                getattr(loc, '航班') == '-':
            df1.drop([num], inplace=True)
        
    df1.sort_values(by='客户标识', axis=0, ascending=True, inplace=True)

    for num, loc in enumerate(df1.itertuples()):
        print(loc)
    df1.to_csv(path_w, index=False)
